﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using log4net;
using System.Reflection;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using FunkeLab;


namespace AnyOffice.general.info.user
{
    public partial class user_list : BasePage
    {
        protected MyTreeViewItem nodeParent;
        protected MyTreeViewItem nodeUser;

        private void LoadDeptTree(ref MyTreeViewItem nodeParent, int DeptId)
        {
            DataTable table = new DepartmentDao().SelectChildAll(base.Conn, DeptId);
            UsersDao dao2 = new UsersDao();
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    MyTreeViewItem item = new MyTreeViewItem();
                    item.Text = (table.Rows[i]["DeptName"] == DBNull.Value) ? "" : table.Rows[i]["DeptName"].ToString();
                    item.Image = "/images/node_dept.gif";
                    DataTable table2 = dao2.SelectBaseByDeptId(base.Conn, Convert.ToInt32(table.Rows[i]["DeptId"].ToString()));
                    if (table2.Rows.Count > 0)
                    {
                        for (int j = 0; j < table2.Rows.Count; j++)
                        {
                            this.nodeUser = new MyTreeViewItem();
                            this.nodeUser.Text = (table2.Rows[j]["UserName"] == DBNull.Value) ? "" : table2.Rows[j]["UserName"].ToString();
                            this.nodeUser.Image = "/images/node_user.gif";
                            this.nodeUser.Link = "/general/ipanel/user_info.aspx?user_id=" + table2.Rows[j]["UserId"].ToString();
                            this.nodeUser.TargetFrame = "user_info";
                            item.Items.Add(this.nodeUser);
                        }
                    }
                    this.LoadDeptTree(ref item, int.Parse(table.Rows[i]["DeptId"].ToString()));
                    nodeParent.Items.Add(item);
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                UsersDao dao = new UsersDao();
                DataTable table = new DepartmentDao().SelectParentAll(base.Conn);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        this.nodeParent = new MyTreeViewItem();
                        this.nodeParent.Text = (table.Rows[i]["DeptName"] == DBNull.Value) ? "" : table.Rows[i]["DeptName"].ToString();
                        this.nodeParent.Image = "/images/node_dept.gif";
                        DataTable table2 = dao.SelectBaseByDeptId(base.Conn, Convert.ToInt32(table.Rows[i]["DeptId"].ToString()));
                        if (table2.Rows.Count > 0)
                        {
                            for (int j = 0; j < table2.Rows.Count; j++)
                            {
                                this.nodeUser = new MyTreeViewItem();
                                this.nodeUser.Text = (table2.Rows[j]["UserName"] == DBNull.Value) ? "" : table2.Rows[j]["UserName"].ToString();
                                this.nodeUser.Image = "/images/node_user.gif";
                                this.nodeUser.Link = "/general/ipanel/user_info.aspx?user_id=" + table2.Rows[j]["UserId"].ToString();
                                this.nodeUser.TargetFrame = "user_info";
                                this.nodeParent.Items.Add(this.nodeUser);
                            }
                        }
                        this.LoadDeptTree(ref this.nodeParent, int.Parse(table.Rows[i]["DeptId"].ToString()));
                        this.TreeView1.Items.Add(this.nodeParent);
                    }
                }
            }
        }

 

    }
}
